<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class playlist_mod extends CI_Model {

    function playlist_mod()
    {
        parent::__construct();
    }
    
    function check_name($name,$user)
    {
        $this->db->select('id');
        $this->db->where('playlist_name', $name);
        $this->db->where('username', $user);
        $i = $this->db->get('user_playlist');

        return $var = ($i->num_rows() > 0) ? $i->row() : false;
    }
    
    function check_song($idplay, $idsong)
    {
        $this->db->select('id');
        $this->db->where('id_user_playlist', $idplay);
        $this->db->where('id_song', $idsong);
        $i = $this->db->get('user_playlist_detail');

        return $var = ($i->num_rows() > 0) ? $i->row() : false;
    }
    
    function add($data=null)
    {
        if($data != null){
            $this->db->insert('user_playlist',$data);
        }
    }
    
    function add_song($data=null)
    {
        if($data != null){
            $this->db->insert('user_playlist_detail',$data);
        }
    }
    
    function delete_song($idplay, $idsong)
    {
        $this->db->where('id_user_playlist', $idplay);
        $this->db->where('id_song', $idsong);
        $this->db->delete('user_playlist_detail');
    }
    
    function get_byuser($username)
    {
        $this->db->select('id, playlist_name');
        $this->db->where('username', $username);
        
        $i = $this->db->get('user_playlist');

        return $var = ($i->num_rows() > 0) ? $i->result_array() : false;
    }
}